/*
 *  ofxJSGlu.cpp
 *  liveCoding
 *
 *  Created by Julien Gachadoat on 20/09/09.
 *  Copyright 2009 2Roqs. All rights reserved.
 *
 */

#include "ofxJSGlu.h"
#include "js/ofxJSGlu.cpp"

//--------------------------------------------------------------
ofxJSGlu* ofxJSGlu::smp_instance = 0;

//--------------------------------------------------------------
ofxJSGlu::ofxJSGlu()
{
}

//--------------------------------------------------------------
ofxJSGlu::~ofxJSGlu()
{
}

//--------------------------------------------------------------
ofxJSGlu* ofxJSGlu::instance()
{
	return smp_instance;
}

//--------------------------------------------------------------
void ofxJSGlu::initialize()
{
	if (smp_instance == 0)
	{
		// Class definition
		ofxJSGlu::JSInit	(ofxJSGetContext(), ofxJSGetGlobalObj());

		// Create cpp instance
		smp_instance				= new ofxJSGlu();
		JSObject* jsInstance		= smp_instance->getJSObject(ofxJSGetContext());

		// Create gl instance
		if (JS_TRUE == JS_DefineProperty(ofxJSGetContext(), ofxJSGetGlobalObj(), "glu", OBJECT_TO_JSVAL(jsInstance), NULL, NULL, JSPROP_ENUMERATE))
			ofLog(OF_LOG_VERBOSE, "- defining 'glu' on globals object");
	}
}

//--------------------------------------------------------------
void ofxJSGlu::finalize()
{
	delete smp_instance;
}

//--------------------------------------------------------------
void ofxJSGlu::Perspective(float fovy,float aspect,float zNear,float zFar)
{
	gluPerspective(fovy,aspect,zNear,zFar);
}

//--------------------------------------------------------------
void ofxJSGlu::LookAt(float eyeX,float eyeY,float eyeZ,float centerX,float centerY,float centerZ,float upX,float upY,float upZ)
{
	gluLookAt(eyeX,eyeY,eyeZ,centerX,centerY,centerZ,upX,upY,upZ);
}

